<%@page import="java.nio.channels.SeekableByteChannel"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.File"%>
<%@page import="Board.DataBank"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%request.setCharacterEncoding("utf-8"); %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>fileDownload.jsp</title>
</head>
<body>
	<jsp:useBean id="bankVo" class="Board.DataBankVo" />
	<jsp:setProperty property="*" name="bankVo" />
	<%
		DataBank bank = new DataBank();
		String savePath = bank.getUploadPath();
		ServletContext content = this.getServletContext();
		String sFilePath = request.getSession().getServletContext().getRealPath("/") + bankVo.getFilename();
		System.out.print("파일경로:"+sFilePath);
		
		//파일을 읽기위한 버퍼정의
		byte[] b = new byte[4096];

		File file = new File(sFilePath);
		FileInputStream in = new FileInputStream(sFilePath);

		//클라이언트의 요청에 따른 응답 정보 셋팅
		String mineType = getServletContext().getMimeType(sFilePath);
		if (mineType == null)
			mineType = "application/octect-stream";
		response.setContentType(mineType);

		//한글 파일명 처리
		String encoding = new String(
				bankVo.getFilename().getBytes("UTF-8"), "8859_1");
		encoding = encoding.replace("+", "%20");

		//다운로드 다이얼로그창 표시
	response.setHeader("Content-Disposition","attachment;filename="+encoding);
	
		//getOutputStream() 오류 방지(더블클릭시도 예방)
			out.clear();
			out=pageContext.pushBody();
		
		// 지정된 경로에 파일 저장
		ServletOutputStream sos= response.getOutputStream();
		int read=0;
		while((read= in.read(b,0,b.length)) != -1){
			sos.write(b,0,read);
				
		}
		sos.flush();
		sos.close();
		in.close();
		%>
</body>
</html>